<?php

namespace App\Console\Commands;

use App\Model\Permission;
use App\Model\Role;
use App\Model\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class RoleInit extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'system:init';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '权限初始化';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $adminuser = User::query()->where('username','admin')->first();
        if(!$adminuser){
            $adminuser = new  User();
        }
        $adminuser->name = 'admin';
        $adminuser->gender = 1;
        $adminuser->username = 'admin';
        $adminuser->password =  bcrypt('password');
        $adminuser->api_token = str_random(60);
        $adminuser->save();
    }
}
